package com.belizer.demo.thread;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class Demo {
    // 主线程等待子线程结束
    public static void main(String[] args) throws InterruptedException {
        System.out.println("开始：" + LocalDateTime.now());
        final AtomicInteger i =new AtomicInteger(0);

        Thread t = new Thread(()->{

            //模拟任务处理
            i.incrementAndGet();
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t.start();


        t.join();
        System.out.println(i.get());
        System.out.println("结束：" + LocalDateTime.now());
    }
}
